package com.example.contestsystem.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /*
    此类将指定目录下的文件暴露出去，使用户能够下载文件
     */

    private static final String UPLOAD_DIR = "D:/Reserved"; // 指定文件保存的目录

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 将指定目录下的文件暴露出去，以便可以通过URL直接访问
        registry.addResourceHandler("/download/**")
                .addResourceLocations("file:" + UPLOAD_DIR + "/");
    }
}
